$(document).ready(function(){
	
	
	//var gUnit = $("#gUnitID").text();
	//alert(gUnit);
	//alert(gStatus);
	/*
	$.ajax({
  		type: "post",
 		url: "hmk/getUnit_findAll.action",
  		success:function(data){
  			$.each(data.unitList,function(i,n){
  				$("<option value="+n.unitId+">"+n.unitName+"</option>").appendTo('#goodUnitID');
			});
			
			//设置选中的select 			
			var gUnit = $("#gUnitID").text();
			//alert(typeID);
			$("#goodUnitID option").each(function(){
				var v = $(this).attr("value");
				if(v==gUnit){
					$(this).attr("selected","selected");
				}
			});
  		}
	});
	
	*/
		$.ajax({
  		type: "post",
 		url: "hmk/getGoodStatus_findAll.action",
  		success:function(data){
  			$.each(data.gsList,function(i,n){
  				$("<option value="+n.gstatusId+">"+n.gstatusName+"</option>").appendTo('#goodstatusID');
			});
			
			//设置选中的select 			
			var gStatus = $("#gStatusID").text();
			//alert(typeID);
			$("#goodstatusID option").each(function(){
				var v = $(this).attr("value");
				if(v==gStatus){
					$(this).attr("selected","selected");
				}
			});
  		}
	});
	
	////////////////////////////
	$("#acceptForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
            //form.submit();   //提交表单
     	var agkuID = $("#agkuID").text();
		var gID=$('#goodID').text();
		var gstatusID=$('#goodstatusID option:selected').val();
		var gNUM=$('#gNumID').val();
		
		$.ajax({
  			type: "post",
 			url: "hmk/saveAidGoodsKU_updateGood.action",
 			data:{
 				  agkuID1:agkuID,gID1:gID,gstatusID1:gstatusID,gNum1:gNUM
 				 },
  			success:showData
		 });
		  
        },
		rules: {
			'goodstatusID':'required',
			'gNumID':{
				required:true,
				digits:true
			}
			
		} ,
		messages: {
			'goodstatusID':'*必选项',
			'gNumID':{
				required:'*必选项',
				digits:'数字'
			}
			
		}
	});
	////////////////
	
	/*
	//更新物资
	$("#update_midG").click(function(){
		//var agkuID = $("#agkuID").text();
		var agkuID = $("#agkuID").text();
		var gID=$('#goodID').text();
		var gstatusID=$('#goodstatusID option:selected').val();
		var gNUM=$('#gNumID').val();
		
		if(gstatusID!==null &&  gstatusID.length!==0 &&
		   gNUM!==null && gNUM.length!==0){
		   $.ajax({
		 
  			type: "post",
 			url: "hmk/saveAidGoodsKU_updateGood.action",
 			data:{
 				  agkuID1:agkuID,gID1:gID,gstatusID1:gstatusID,gNum1:gNUM
 				 },
  			success:showData
		 });
		 }else{
			alert("带*号的必填！");
		}
		//alert(agkuID);
		//window.location.href="/ag/hmk/findOneAGKU_findAGKUByID.action?agkuID1="+agkuID;
	});
	
	*/
	
	//返回物品维护
	$("#back_agku").click(function(){
		var agkuID = $("#agkuID").text();
		//alert(agkuID);
		window.location.href="/ag/hmk/findOneAGKU_findAGKUByID.action?agkuID1="+agkuID;
	});
	
	
});

function showData(data){
		if(data.ajaxRST=='1'){
			alert("保存成功！");
			//$('#mainFrame',window.parent.document).attr('src','hmk/.jsp');
			var agkuID = $("#agkuID").text();
			window.location.href="/ag/hmk/findOneAGKU_findAGKUByID.action?agkuID1="+agkuID;
		}else{
			alert("保存失败！");
		}
	}